/**
 * Created by chesw on 2017/5/11.
 * describe：病例列表
 */
var casesList = Vue.extend({
    props: ['visitRecord'],
    data: function () {
        return {           
            pageInfo: {
                allRecord: [],
                curPageRecord: [],
                totalCount: "",
                pageSize: 10,
                pageCount: 10,
                pageCurrent: 1
            },
            showLoad:false
        }
    },
    created: function () {
        var _self = this;
       _self.getCasesList();           
    },
    methods: {
        ShowPageBox: function (p_show, p_pageObject) {
            var resultEmpty = document.getElementById("result-empty");
            var pageBox = document.getElementById("clinic-page-box");
            if (p_show) {
                resultEmpty.style.display = "none";
                if (p_pageObject.pageCount <= 1)
                    pageBox.style.display = "none";
                else
                    pageBox.style.display = "block";
            }
            else {
                pageBox.style.display = "none";
                resultEmpty.style.display = "block";
            }
        },
        getCasesList: function (){
            var _self = this;
            var pageBox = document.getElementById("clinic-page-box");
            pageBox.style.display = "none";
            _self.showLoad = true;          
            
            _self.$http.post("/PersonalCenter/GetCasesList", _self.visitRecord).then(function (res) {
                if (res.body.length > 0) {
                    for (var i = 0; i < res.body.length; i++) {
                        _self.pageInfo.allRecord.push(res.body[i]);
                    }
                    _self.pageInfo.totalCount = _self.pageInfo.allRecord.length;
                    _self.pageInfo = showPageRecords(1, _self.pageInfo);
                    _self.showPage();
                    _self.showLoad = false;
                    _self.ShowPageBox(true, _self.pageInfo);
                }
                else {
                    _self.showLoad = false;
                    _self.ShowPageBox(false);
                }
            });          
        },
        detail: function (p_index) {
            var _self = this;
            var param = _self.pageInfo.allRecord[p_index];
            _self.$emit('detail', Personal.CASESDETAIL, param);
        },
        showPage: function () {
            var _self = this;
            var pageBox = document.getElementById("clinic-page-box");

            if (_self.pageInfo.pageCount === 1)
                pageBox.style.display = "none";
            else
                pageBox.style.display = "block";

            var param = {
                pageCount: _self.pageInfo.pageCount,
                curPage: _self.pageInfo.pageCurrent,
                pageInfo:_self.pageInfo,
                page_func: function (p_curPage,p_pageInfo) {
                    showPageRecords(p_curPage, p_pageInfo);
                }                
            };
            _self.$emit('show', param);
        }      
    }, 
    template: '<div class="cases-list">' +
        '<ul v-for=" (item, index) in pageInfo.curPageRecord">' +
            '<li class="cases-one">' +
                '<div class="l-case-one">' +
                    '<div class="date">' +
                        '<p class="month-day">{{item.visitMonthDay}}</p>' +
                        '<p class="year">{{item.visitYear}}</p>' +
                    '</div>' +
                '</div>' +
                '<div class="r-case-one">' +
                    '<img class="process" src="/styles/image/icon/process_green.png">' +
                    '<div class="doctor-info flex">' +
                        '<img :src="item.photoPicUrl" onerror="javascript:this.src=\'/Styles/image/default_head.png\'">' +
                        '<span class="name">{{item.doctorName}} &nbsp;&nbsp;</span>' +
                        '<span class="worker">[{{item.department}} - {{item.title}}] &nbsp;</span>' +
                        '<span class="doctor-type">{{item.visitType}}</span>' +
                        '<a :href="[\'/CaseDetail/Index?caseId=\'+item.caseId+\'&orgId=\'+item.OrgId+\'&visitID=\'+item.visitId]"  target="_blank" class="detail-btn">查看详情</a>' +
                    '</div>' +
                    '<div class="diagnostic-result">' +
                        '<div class="result">' +
                            '<span class="title">就诊人</span>' +
                            '<span class="value">{{item.visitName}} </span>' +
                        '</div>' +
                        '<div class="result">' +
                            '<span class="title">主&nbsp;&nbsp;&nbsp;&nbsp;诉</span>' +
                            '<span class="value">{{item.symptom}}</span>' +
                        '</div>' +
                        '<div class="result">' +
                            '<span class="title">诊断结果</span>' +
                            '<span class="value row-overflow">{{item.diagnosicResult}}</span>' +
                        '</div>' +
                        '<div class="result">' +
                            '<span class="title">诊断建议</span>' +
                            '<span class="value">{{item.advise}}</span>' +
                        '</div>' +
                    '</div>' +
                '</div>' +
            '</li>' +
        '</ul>' +
        '<div class="loading" id="loading" :class="[showLoad?\'show\':\'hide\']"><img src="/styles/image/loading.gif"></div>' +
        '<div class="result-empty" id="result-empty">暂无数据</div>' +
    '</div>'
});